package com.wanfeng.common.handler;

import com.wanfeng.common.Result;
import com.wanfeng.common.exception.WanfengException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    //处理特定异常,自定义的异常
    @ExceptionHandler(WanfengException.class)
    @ResponseBody
    public Result specialException(WanfengException e){
        e.printStackTrace();
        return Result.fail().message(e.getMessage()).code(e.getCode());
    }
}
